package com.akka.demo.controller;

import com.akka.demo.actor.DeviceGroup;
import com.akka.demo.service.DemoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by Administrator on 2018/2/26.
 */
@RestController
@RequestMapping("demo")
public class DemoController {

    @Autowired
    private DemoService demoService;

    @GetMapping("start")
    public Object startApp(@RequestParam("msg") String msg) {
        if (msg.equals("query")) {
            demoService.startApp(new DeviceGroup.RequestAllTemperatures(123L));
        } else {
            demoService.startApp(msg);

        }
        Map<String, Object> map = new HashMap<>();
        map.put("msg", "done");
        return map;
    }

    @GetMapping("stop")
    public Object stopApp() {
        demoService.stopApp();
        Map<String, Object> map = new HashMap<>();
        map.put("msg", "done");
        return map;
    }
}
